home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Module Com22378772001.psc / colFiles.cls next >
Encoding:
Visual Basic class definition  |  2001-06-26  |  5.3 KB  |  185 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "colFiles"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Collection" ,"clsFile"
  16. Attribute VB_Ext_KEY = "Member0" ,"clsFile"
  17. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  18. Option Explicit
  19.  
  20.  
  21. 'local variable to hold collection
  22. Private mCol As Collection
  23. Public Function LoadFiles( _
  24.                         ByVal sFileSpec As String, _
  25.                         Optional ByVal bRecursive As Boolean = False, _
  26.                         Optional ByVal pb) _
  27.                 As Long
  28.     
  29.     Static lLevel As Long
  30.     lLevel = lLevel + 1
  31.     If lLevel = 1 Then
  32.         Set mCol = Nothing
  33.         Set mCol = New Collection
  34.     End If
  35.     
  36.     On Error Resume Next
  37.     pb.Min = 0
  38.     pb.Value = 0
  39.     pb.Max = ts.fileCount(sFileSpec) + 1
  40.     On Error GoTo 0
  41.     
  42.     Dim lFind As Long, lMatch As Long
  43.     Dim tInfo As WIN32_FIND_DATA
  44.     Dim oFile As clsFile
  45.     
  46.     ' Scan Subdirs First
  47.     If bRecursive Then
  48.         Dim sDirSpec As String
  49.         Dim sSpec As String
  50.         sSpec = ts.sFilename(sFileSpec, efpFileNameAndExt)
  51.         sDirSpec = ts.sAppend(ts.sFilename(sFileSpec, efpFilePath), "\")
  52.         lFind = FindFirstFile(sDirSpec & "*.*", tInfo)
  53.         lMatch = 99
  54.         Do While lFind > 0 And lMatch > 0
  55.             If (tInfo.dwFileAttributes And efaDIRECTORY) > 0 Then
  56.                 Dim sDirName As String
  57.                 sDirName = sNT(tInfo.cFileName)
  58.                 If sDirName <> "." And sDirName <> ".." Then
  59.                     LoadFiles sDirSpec & sAppend(sDirName, "\") & sSpec, bRecursive, pb
  60.                 End If
  61.             End If
  62.             lMatch = FindNextFile(lFind, tInfo)
  63.         Loop
  64.         FindClose lFind
  65.     End If
  66.     
  67.     lFind = FindFirstFile(sFileSpec, tInfo)
  68.     lMatch = 99
  69.     Do While lFind > 0 And lMatch > 0
  70.         If Not (tInfo.dwFileAttributes And efaDIRECTORY) > 0 Then
  71.             Set oFile = New clsFile
  72.             oFile.sFilename = ts.sFilename(sFileSpec, efpFilePath) & ts.sNT(tInfo.cFileName)
  73.             mCol.Add oFile
  74.         End If
  75.         lMatch = FindNextFile(lFind, tInfo)
  76.         On Error Resume Next
  77.         pb.Value = pb.Value + 1
  78.         pb.Refresh
  79.         On Error GoTo 0
  80.     Loop
  81.     FindClose lFind
  82.     LoadFiles = mCol.Count
  83.     lLevel = lLevel - 1
  84.     
  85. End Function
  86.  
  87. Public Function Clear()
  88.     Set mCol = Nothing
  89.     Set mCol = New Collection
  90. End Function
  91.  
  92.  
  93. Public Function Add(ByVal sFilename As String, Optional sKey As String) As clsFile
  94.     'create a new object
  95.     Dim objNewMember As clsFile
  96.     Set objNewMember = New clsFile
  97.     objNewMember.sFilename = sFilename
  98.     If Len(sKey) = 0 Then
  99.         On Error Resume Next
  100.         mCol.Add objNewMember, sFilename
  101.         On Error GoTo 0
  102.     Else
  103.         mCol.Add objNewMember, sKey
  104.     End If
  105.  
  106.     'set the properties passed into the method
  107. '    objNewMember.sPathNetwork = sPathNetwork
  108. '    objNewMember.sPathDOS = sPathDOS
  109. '    objNewMember.sExtension = sExtension
  110. '    objNewMember.sName = sName
  111. '    objNewMember.dLastModified = dLastModified
  112. '    objNewMember.lSize = lSize
  113. '    If IsObject(lAttributes) Then
  114. '        Set objNewMember.lAttributes = lAttributes
  115. '    Else
  116. '        objNewMember.lAttributes = lAttributes
  117. '    End If
  118. '    objNewMember.sINIsection = sINIsection
  119. '    objNewMember.sFilename = sFilename
  120. '    objNewMember.sFullPathNetwork = sFullPathNetwork
  121. '    objNewMember.sFullPathDOS = sFullPathDOS
  122. '    If Len(sKey) = 0 Then
  123. '        mCol.Add objNewMember
  124. '    Else
  125. '        mCol.Add objNewMember, sKey
  126. '    End If
  127.  
  128.  
  129.     'return the object created
  130.     Set Add = objNewMember
  131.     Set objNewMember = Nothing
  132.  
  133.  
  134. End Function
  135.  
  136. Public Property Get Item(vntIndexKey As Variant) As clsFile
  137. Attribute Item.VB_UserMemId = 0
  138.     'used when referencing an element in the collection
  139.     'vntIndexKey contains either the Index or Key to the collection,
  140.     'this is why it is declared as a Variant
  141.     'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
  142.   Set Item = mCol(vntIndexKey)
  143. End Property
  144.  
  145.  
  146.  
  147. Public Property Get Count() As Long
  148.     'used when retrieving the number of elements in the
  149.     'collection. Syntax: Debug.Print x.Count
  150.     Count = mCol.Count
  151. End Property
  152.  
  153.  
  154. Public Sub Remove(vntIndexKey As Variant)
  155.     'used when removing an element from the collection
  156.     'vntIndexKey contains either the Index or Key, which is why
  157.     'it is declared as a Variant
  158.     'Syntax: x.Remove(xyz)
  159.  
  160.  
  161.     mCol.Remove vntIndexKey
  162. End Sub
  163.  
  164.  
  165. Public Property Get NewEnum() As clsFile
  166. Attribute NewEnum.VB_UserMemId = -4
  167. Attribute NewEnum.VB_MemberFlags = "40"
  168.     'this property allows you to enumerate
  169.     'this collection with the For...Each syntax
  170.     Set NewEnum = mCol.[_NewEnum]
  171. End Property
  172.  
  173.  
  174. Private Sub Class_Initialize()
  175.     'creates the collection when this class is created
  176.     Set mCol = New Collection
  177. End Sub
  178.  
  179.  
  180. Private Sub Class_Terminate()
  181.     'destroys collection when this class is terminated
  182.     Set mCol = Nothing
  183. End Sub
  184.  
  185.